package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.converter.ShoppingCategoriesConverter;
import com.cskaoyan.shopping.dal.entitys.ItemCat;
import com.cskaoyan.shopping.dal.persistence.ItemCatMapper;
import com.cskaoyan.shopping.dto.ShoppingCategoriesDto;
import com.cskaoyan.shopping.dto.ShoppingCategoriesResponse;
import com.cskaoyan.shopping.dto.ShoppingNavigationResponse;
import com.cskaoyan.shopping.service.ShoppingCategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类说明
 *
 * @author zhangfuqiang
 * @date 2022/5/19
 */
@Service
public class ShoppingCategoriesServiceImpl implements ShoppingCategoriesService {
    @Autowired
    ItemCatMapper itemCatMapper;

    @Autowired
    ShoppingCategoriesConverter shoppingCategoriesConverter;

    @Override
    public ShoppingCategoriesResponse getShoppingCategories() {
        ShoppingCategoriesResponse shoppingCategoriesResponse = new ShoppingCategoriesResponse();
        try {
            //拿到查询数据
            List<ItemCat> itemCats = itemCatMapper.selectAll();

            //转换数据
            List<ShoppingCategoriesDto> shoppingCategoriesDtos = shoppingCategoriesConverter.itemCatsDo2ShoppingCategoriesDtos(itemCats);
            shoppingCategoriesResponse.setResponse(shoppingCategoriesDtos);
            shoppingCategoriesResponse.setTimestamp(System.currentTimeMillis());
            shoppingCategoriesResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            shoppingCategoriesResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionProcessorUtils.wrapperHandlerException(shoppingCategoriesResponse, e);
        }

        return shoppingCategoriesResponse;
    }
}
